package com.cskaoyan.wordmemorize.controller.admin;

import com.cskaoyan.wordmemorize.auth.SaAdminCheckPermission;
import com.cskaoyan.wordmemorize.common.result.Result;
import com.cskaoyan.wordmemorize.dto.admin.DeleteLevelOperateDTO;
import com.cskaoyan.wordmemorize.dto.admin.LevelDTO;
import com.cskaoyan.wordmemorize.dto.admin.PageDTO;
import com.cskaoyan.wordmemorize.request.BatchDeleteCommand;
import com.cskaoyan.wordmemorize.request.LevelCommand;
import com.cskaoyan.wordmemorize.request.PageRequest;
import com.cskaoyan.wordmemorize.service.LevelService;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/level")
public class AdminLevelController {

    @Autowired
    LevelService levelService;


    // 添加等级(后台等级权限管理-等级管理)
    @SaAdminCheckPermission("admin:level:add")
    @PostMapping("")
    public Result addLevel(@RequestBody LevelCommand command){
        levelService.addLevel(command);
        return Result.ok();
    }

    // 修改等级(后台等级权限管理-等级管理)
    @SaAdminCheckPermission("admin:level:update")
    @PutMapping("")
    public Result updateLevel(@RequestBody LevelCommand command){
        levelService.updateLevel(command);
        return Result.ok();
    }

    // 分页查询等级(后台等级权限管理-等级管理)
    @SaAdminCheckPermission("admin:level:search")
    @GetMapping("list")
    public Result<PageDTO<LevelDTO>> getLevelList(PageRequest request){
        PageDTO<LevelDTO> levelList = levelService.getLevelList(request);
        return Result.ok(levelList);
    }

    // 删除等级(后台等级权限管理-等级管理)
    @SaAdminCheckPermission("admin:leveldelete")
    @DeleteMapping("{id}")
    public Result<DeleteLevelOperateDTO> deleteLevel(@PathVariable("id") Long id){
        DeleteLevelOperateDTO deleteLevelOperateDTO = levelService.deleteLevel(id);
        return Result.ok(deleteLevelOperateDTO);
    }

    // 批量删除等级(后台等级权限管理-等级管理)
    @SaAdminCheckPermission("admin:level:batchdelete")
    @DeleteMapping("batch")
    public Result<List<DeleteLevelOperateDTO>> deleteLevels(@RequestBody BatchDeleteCommand command){
        List<DeleteLevelOperateDTO> deleteLevelOperateDTOS = levelService.deleteLevels(command);
        return Result.ok(deleteLevelOperateDTOS);
    }
}
